﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Data;
using System.Configuration;

public partial class product_saving_user_saving_summary : System.Web.UI.Page
{

    protected void Page_Load(object sender, EventArgs e)
    {

        ((AfterLogin)this.Master).mainCategory = "ACCOUNTS";
        SqlConnection conn = DBManager.getSqlConnection();


       // this.lbAccNoA.Text = Session["savingAccountNo"] as String;

        string sql = "select accountNo ,balance from  SAVING_ACCOUNT where custID = '" + Session["userId"] + "'";
        SqlCommand cmd = new SqlCommand(sql, conn);
        cmd.Connection.Open();
        SqlDataReader dr = cmd.ExecuteReader();
    

        //this.lbAccBalanceA.Text = Session["balance"] as String;
       
        String saving_acc = this.lbAccNoA.Text;

        if (saving_acc.StartsWith("520050"))
        {
            this.lbacctType.Text = "KidSaver Saving Account";

        }
        else
        {

            this.lbacctType.Text = "PowerSave Saving Account";
        }

        if (dr.Read())
        {
            lbAccNoA.Text = dr.GetString(0); // assign to your label
            this.lbAccBalanceA.Text = dr.GetDecimal(1) + "";

        }
        cmd.Connection.Close();


        if (Page.IsPostBack == false)
        {
                  
        }

    }
    protected void btnSubmit_Click(object sender, EventArgs e)
    {
        string strConnectionString = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
        SqlConnection myConnection = new SqlConnection(strConnectionString);

        String command = "";
        if (ddlTransaction.SelectedItem.Value == "current")
        {
            command = "SELECT  transactionID, CONVERT(nvarchar(20),transactionDate,103) AS transactionDate, transactionType, transactionStatus, CASE WHEN transactionAmount >=0 THEN transactionAmount END AS credit, CASE WHEN transactionAmount <0 THEN transactionAmount END AS debit"
                + " FROM SUMMARY WHERE transactionDate BETWEEN '2013-08-01' AND '2013-08-31' AND accountNo ='" + lbAccNoA.Text + "'";
        }

        if (ddlTransaction.SelectedItem.Value == "one")
        {
            command = "SELECT  transactionID, CONVERT(nvarchar(20),transactionDate,103) AS transactionDate, transactionType, transactionStatus, CASE WHEN transactionAmount >=0 THEN transactionAmount END AS credit, CASE WHEN transactionAmount <0 THEN transactionAmount END AS debit"
              + " FROM SUMMARY WHERE transactionDate BETWEEN '2013-07-01' AND '2013-08-31' AND accountNo ='" + lbAccNoA.Text + "'"; 
        }

        if (ddlTransaction.SelectedItem.Value == "two")
        {
            command = "SELECT  transactionID, CONVERT(nvarchar(20),transactionDate,103) AS transactionDate, transactionType, transactionStatus, CASE WHEN transactionAmount >=0 THEN transactionAmount END AS credit, CASE WHEN transactionAmount <0 THEN transactionAmount END AS debit"
              + " FROM SUMMARY WHERE transactionDate BETWEEN '2013-06-01' AND '2013-08-31' AND accountNo ='" + lbAccNoA.Text + "'";
        }

        // replace "SELECT * from SUMMARY" by command
        SqlCommand myCommand = new SqlCommand(command, myConnection);
        //Open Connection
        myConnection.Open();
        //Execute Command using a DATAREADER
        SqlDataReader myReader = myCommand.ExecuteReader();
        //Retrieving Data from DataReader
        gvTransaction.DataSource = myReader;
        //Bind the control to the datasource
        gvTransaction.DataBind();
        
        //Close the data reader
        myReader.Close();
        //Close the connection
        myConnection.Close();
       
    }
}

